from waftools.pebble_test import clar, get_bitdepth_for_platform
import waflib.Utils

def _process_template(task):
    from string import Template
    template = Template(open(task.inputs[0].srcpath(), 'r').read())
    processed = template.safe_substitute(BIT_DEPTH_NAME=task.generator.bit_depth_name)
    waflib.Utils.writef(task.outputs[0].srcpath(), processed)

def graphics_process_test_template(ctx, source, bit_depth):
    path = ctx.path.find_node(source).srcpath()
    bit_depth_name = "{}bit".format(bit_depth)

    # Format the output filename.
    #   - ".template.c" => ".auto.c"
    #   - Add bit depth to filename
    # eg. "test_graphics.template.c" => "test_graphics_8bit.c"
    split = source.replace("template.", "").split('.')
    target_name = split[0] + '_' + bit_depth_name + '.' + split[1]

    out_path = ctx.path.get_bld().make_node(target_name)

    ctx(name='generate_test_from_template', rule=_process_template, source=ctx.path.find_node(source),
        target=out_path, bit_depth_name=bit_depth_name)
    return out_path


def build(ctx):
    graphics_sources_ant_glob = \
        " src/fw/applib/graphics/${BITDEPTH}_bit/framebuffer.c" \
        " src/fw/applib/graphics/framebuffer.c" \
        " src/fw/applib/graphics/gbitmap.c" \
        " src/fw/applib/graphics/gcolor_definitions.c" \
        " src/fw/applib/graphics/gtypes.c" \
        " src/fw/applib/graphics/graphics.c" \
        " src/fw/applib/graphics/graphics_bitmap.c" \
        " src/fw/applib/graphics/gtransform.c" \
        " src/fw/applib/graphics/bitblt.c" \
        " src/fw/applib/graphics/${BITDEPTH}_bit/bitblt_private.c" \
        " src/fw/applib/ui/layer.c" \
        " src/fw/applib/ui/bitmap_layer.c" \
        " tests/fakes/fake_display.c" \
        " tests/fakes/fake_gbitmap_png.c" \
        " src/fw/applib/graphics/graphics_private.c" \
        " src/fw/applib/graphics/graphics_private_raw.c" \
        " src/fw/applib/graphics/graphics_circle.c" \
        " src/fw/applib/graphics/graphics_line.c" \
        " src/fw/applib/graphics/gpath.c"

    graphics_test_sources = [
        "test_framebuffer.template.c",
        "test_graphics_draw_pixel.template.c",
        "test_graphics_draw_stroke.template.c",
        "test_graphics_draw_rect.template.c",
        "test_graphics_fill_rect.template.c",
        "test_graphics_draw_circle.template.c",
        "test_graphics_stroke_circle.template.c",
        "test_graphics_fill_circle.template.c",
        "test_graphics_draw_round_rect.template.c",
        "test_graphics_gpath.template.c",
        "test_graphics_gtransform.template.c",
        "test_graphics_context.template.c",
        "test_blending.template.c",
        "test_graphics_draw_stroke_precise.template.c"
    ]

    for platform in ['tintin', 'snowy']:
        bit_depth = get_bitdepth_for_platform(ctx, platform)
        defines = ctx.env.test_image_defines
        for test in graphics_test_sources:
            generated_source = graphics_process_test_template(ctx, test, bit_depth)
            clar(ctx,
                    sources_ant_glob=graphics_sources_ant_glob,
                    test_sources=[generated_source],
                    add_includes=[ctx.path.abspath()],
                    defines=defines,
                    platforms=[platform])

    clar(ctx,
         sources_ant_glob=" src/fw/applib/graphics/${BITDEPTH}_bit/bitblt_private.c"
                          " src/fw/applib/graphics/${BITDEPTH}_bit/framebuffer.c"
                          " src/fw/applib/graphics/bitblt.c"
                          " src/fw/applib/graphics/framebuffer.c"
                          " src/fw/applib/graphics/gbitmap.c"
                          " src/fw/applib/graphics/gbitmap_png.c"
                          " src/fw/applib/graphics/gcolor_definitions.c"
                          " src/fw/applib/graphics/graphics.c"
                          " src/fw/applib/graphics/graphics_bitmap.c"
                          " src/fw/applib/graphics/graphics_circle.c"
                          " src/fw/applib/graphics/graphics_line.c"
                          " src/fw/applib/graphics/graphics_private.c"
                          " src/fw/applib/graphics/graphics_private_raw.c"
                          " src/fw/applib/graphics/gtypes.c"
                          " src/fw/applib/ui/bitmap_layer.c"
                          " src/fw/applib/ui/layer.c"
                          " src/fw/applib/vendor/tinflate/tinflate.c"
                          " src/fw/applib/vendor/uPNG/upng.c",
         test_sources_ant_glob='test_graphics_draw_bitmap.c',
         defines=ctx.env.test_image_defines,
         platforms=['snowy', 'silk'])

    templated_graphics_draw_text_sources_ant_glob = \
        " src/fw/applib/graphics/{depth_dir}/framebuffer.c" \
        " src/fw/applib/graphics/framebuffer.c" \
        " src/fw/applib/graphics/gcolor_definitions.c" \
        " src/fw/applib/graphics/gtypes.c" \
        " src/fw/applib/graphics/gbitmap.c" \
        " src/fw/applib/graphics/graphics.c" \
        " src/fw/applib/graphics/gtransform.c" \
        " src/fw/applib/graphics/bitblt.c" \
        " src/fw/applib/graphics/{depth_dir}/bitblt_private.c" \
        " src/fw/applib/ui/layer.c" \
        " tests/fakes/fake_gbitmap_get_data_row.c" \
        " tests/fakes/fake_gbitmap_png.c" \
        " tests/fakes/fake_display.c" \
        " src/fw/applib/graphics/text_render.c" \
        " src/fw/applib/graphics/utf8.c" \
        " src/fw/applib/graphics/text_layout.c" \
        " src/fw/applib/graphics/perimeter.c" \
        " src/fw/applib/graphics/text_resources.c" \
        " src/fw/flash_region/flash_region.c" \
        " src/fw/flash_region/filesystem_regions.c" \
        " src/fw/system/hexdump.c" \
        " src/fw/applib/fonts/codepoint.c" \
        " src/fw/resource/resource.c" \
        " src/fw/resource/resource_storage.c" \
        " src/fw/resource/resource_storage_builtin.c" \
        " src/fw/resource/resource_storage_file.c" \
        " src/fw/resource/resource_storage_flash.c" \
        " src/fw/services/normal/filesystem/flash_translation.c" \
        " src/fw/services/normal/filesystem/pfs.c" \
        " src/fw/services/normal/filesystem/app_file.c" \
        " src/fw/util/crc8.c" \
        " src/fw/util/legacy_checksum.c" \
        " src/fw/drivers/flash/flash_crc.c" \
        " tests/fakes/fake_fonts.c" \
        " tests/fakes/fake_rtc.c" \
        " tests/fakes/fake_spi_flash.c" \
        " tests/fixtures/resources/builtin_resources.auto.c" \
        " tests/fixtures/resources/pfs_resource_table.c" \
        " src/fw/applib/graphics/graphics_private.c" \
        " src/fw/applib/graphics/graphics_private_raw.c" \
        " src/fw/applib/graphics/graphics_circle.c" \
        " src/fw/applib/graphics/graphics_line.c"

    graphics_draw_text_test_sources = [
        "test_graphics_draw_text.template.c"
    ]

    for platform in ['tintin', 'snowy']:
        bit_depth = 1 if platform == 'tintin' else 8
        depth_dir = '{}_bit'.format(bit_depth)
        graphics_sources_ant_glob = templated_graphics_draw_text_sources_ant_glob.format(depth_dir=depth_dir)

        defines = ctx.env.test_image_defines
        for test in graphics_draw_text_test_sources:
            generated_source = graphics_process_test_template(ctx, test, bit_depth)
            clar(ctx,
                    sources_ant_glob=graphics_sources_ant_glob,
                    test_sources=[generated_source],
                    add_includes=[ctx.path.abspath()],
                    defines=defines,
                    override_includes=['dummy_board'],
                    platforms=[platform])

    clar(ctx,
        sources_ant_glob=templated_graphics_draw_text_sources_ant_glob.format(depth_dir="8_bit"),
        test_sources_ant_glob='test_graphics_draw_text_flow.c',
        defines = ctx.env.test_image_defines,
        override_includes=['dummy_board'])


    # All tests that are bit-depth agnostic should follow.
    clar(ctx,
        sources_ant_glob = \
            " src/fw/applib/graphics/gcolor_definitions.c" \
            " src/fw/applib/graphics/gtypes.c", \
        test_sources_ant_glob = "test_graphics_colors.c")

    clar(ctx,
        sources_ant_glob = \
            " src/fw/applib/graphics/gtypes.c",
        test_sources_ant_glob = "test_gtypes.c",
        platforms=["tintin", "snowy", "spalding"])

    clar(ctx,
        sources_ant_glob = \
            " src/fw/applib/graphics/gtypes.c" \
            " src/fw/applib/graphics/graphics_circle.c",
        test_sources_ant_glob = "test_graphics_circle.c")

    clar(ctx,
        sources_ant_glob = \
            " src/fw/applib/graphics/gtypes.c" \
            " tests/fakes/fake_gbitmap_png.c" \
            " tests/fakes/fake_resource_syscalls.c" \
            " src/fw/applib/graphics/gbitmap.c",
        test_sources_ant_glob = "test_gbitmap_data_row_info.c")

    clar(ctx,
        sources_ant_glob = \
            " src/fw/applib/graphics/gbitmap.c" \
            " src/fw/applib/graphics/gtypes.c" \
            " tests/fakes/fake_applib_resource.c",
        test_sources_ant_glob = "test_gbitmap_resource_validation.c")

    clar(ctx,
        sources_ant_glob = \
            " src/fw/applib/graphics/gtypes.c" \
            " tests/fakes/fake_gbitmap_png.c" \
            " tests/fakes/fake_resource_syscalls.c" \
            " src/fw/applib/graphics/gbitmap.c",
        test_sources_ant_glob = "test_gbitmap_formats.c",
        platforms=["tintin", "snowy", "spalding"])

    clar(ctx,
         sources_ant_glob = \
             " src/fw/applib/graphics/framebuffer.c" \
             " src/fw/applib/graphics/gbitmap.c" \
             " src/fw/applib/graphics/8_bit/framebuffer.c" \
             " src/fw/applib/graphics/gcolor_definitions.c" \
             " src/fw/applib/graphics/graphics.c" \
             " src/fw/applib/graphics/graphics_bitmap.c" \
             " src/fw/applib/graphics/gtypes.c" \
             " tests/fakes/fake_gbitmap_png.c" \
             " tests/fakes/fake_resource_syscalls.c" \
             " tests/fakes/fake_applib_resource.c" \
             " tests/stubs/stubs_bitblt.c",
         test_sources_ant_glob = "test_gbitmap_processor.c")

    clar(ctx,
        sources_ant_glob = \
            " src/fw/applib/graphics/gtypes.c" \
            " src/fw/applib/graphics/gcolor_definitions.c" \
            " src/fw/applib/graphics/gbitmap.c" \
            " src/fw/applib/graphics/graphics.c" \
            " src/fw/applib/graphics/graphics_private.c" \
            " src/fw/applib/graphics/graphics_private_raw.c" \
            " src/fw/applib/graphics/bitblt.c" \
            " src/fw/applib/graphics/8_bit/bitblt_private.c", \
        test_sources_ant_glob = "test_graphics_blending.c",
        platforms=['snowy'])


    clar(ctx,
        sources_ant_glob = \
            " src/fw/applib/graphics/gcolor_definitions.c" \
            " src/fw/applib/graphics/gdraw_command.c" \
            " src/fw/applib/graphics/gdraw_command_list.c" \
            " src/fw/applib/graphics/gdraw_command_image.c" \
            " src/fw/applib/graphics/gdraw_command_frame.c",
        test_sources_ant_glob = "test_gdraw_command.c")

    clar(ctx,
        sources_ant_glob = \
            " src/fw/applib/graphics/gcolor_definitions.c" \
            " src/fw/applib/graphics/gdraw_command.c" \
            " src/fw/applib/graphics/gdraw_command_list.c" \
            " src/fw/applib/graphics/gdraw_command_frame.c" \
            " src/fw/applib/graphics/gdraw_command_sequence.c",
        test_sources_ant_glob = "test_gdraw_command_sequence.c")

    clar(ctx,
        sources_ant_glob = \
            " src/fw/applib/graphics/gcolor_definitions.c" \
            " src/fw/applib/graphics/gbitmap.c" \
            " src/fw/applib/graphics/gtypes.c" \
            " src/fw/applib/graphics/gdraw_command.c" \
            " src/fw/applib/graphics/gdraw_command_list.c" \
            " src/fw/applib/graphics/gdraw_command_frame.c" \
            " src/fw/applib/graphics/gdraw_command_image.c" \
            " src/fw/applib/graphics/gdraw_command_sequence.c" \
            " tests/fakes/fake_gbitmap_png.c" \
            " tests/fakes/fake_resource_syscalls.c" \
            " tests/fakes/fake_applib_resource.c",
        runtime_deps=ctx.env.test_pdcs,
        defines=ctx.env.test_image_defines,
        test_sources_ant_glob = "test_gdraw_command_resources.c")

    clar(ctx,
        sources_ant_glob = \
            " src/fw/applib/graphics/8_bit/framebuffer.c" \
            " src/fw/applib/graphics/framebuffer.c" \
            " src/fw/applib/graphics/gcolor_definitions.c" \
            " src/fw/applib/graphics/gtypes.c" \
            " src/fw/applib/graphics/gbitmap.c" \
            " src/fw/applib/graphics/graphics.c" \
            " src/fw/applib/graphics/graphics_private.c" \
            " src/fw/applib/graphics/graphics_private_raw.c" \
            " src/fw/applib/graphics/graphics_line.c" \
            " src/fw/applib/graphics/graphics_circle.c" \
            " src/fw/applib/graphics/gpath.c" \
            " src/fw/applib/graphics/bitblt.c" \
            " src/fw/applib/graphics/8_bit/bitblt_private.c" \

            " src/fw/applib/ui/animation_interpolate.c" \
            " src/fw/applib/ui/animation_timing.c" \

            " tests/fakes/fake_gbitmap_png.c" \

            " tests/fw/graphics/weather_app_resources.c" \

            " src/fw/applib/graphics/gdraw_command.c" \
            " src/fw/applib/graphics/gdraw_command_frame.c" \
            " src/fw/applib/graphics/gdraw_command_list.c" \
            " src/fw/applib/graphics/gdraw_command_image.c" \
            " src/fw/applib/graphics/gdraw_command_transforms.c", \
        test_sources_ant_glob = "test_gdraw_command_transforms.c",
        defines=ctx.env.test_image_defines,
        override_includes=['dummy_board'])

    clar(ctx,
        sources_ant_glob =
            " src/fw/applib/vendor/uPNG/upng.c"
            " src/fw/applib/vendor/tinflate/tinflate.c"
            " src/fw/applib/graphics/gbitmap.c" \
            " src/fw/applib/graphics/gbitmap_png.c"
            " src/fw/applib/graphics/gcolor_definitions.c"
            " src/fw/applib/graphics/8_bit/framebuffer.c"
            " src/fw/applib/graphics/framebuffer.c"
            " src/fw/applib/graphics/graphics.c"
            " src/fw/applib/graphics/8_bit/bitblt_private.c"
            " src/fw/applib/graphics/bitblt.c"
            " src/fw/applib/graphics/graphics_private.c"
            " src/fw/applib/graphics/graphics_private_raw.c"
            " src/fw/applib/graphics/graphics_circle.c"
            " src/fw/applib/graphics/graphics_line.c"
            " src/fw/applib/graphics/gtypes.c",
        runtime_deps=ctx.env.pdcs2png_test_files,
        test_sources_ant_glob="test_pdc.c",
        defines=ctx.env.test_image_defines)

    clar(ctx,
        sources_ant_glob =
            " src/fw/applib/vendor/uPNG/upng.c"
            " src/fw/applib/vendor/tinflate/tinflate.c"
            " src/fw/applib/graphics/gbitmap.c" \
            " src/fw/applib/graphics/gbitmap_png.c"
            " src/fw/applib/graphics/gcolor_definitions.c"
            " src/fw/applib/graphics/8_bit/framebuffer.c"
            " src/fw/applib/graphics/framebuffer.c"
            " src/fw/applib/graphics/graphics.c"
            " src/fw/applib/graphics/8_bit/bitblt_private.c"
            " src/fw/applib/graphics/bitblt.c"
            " src/fw/applib/graphics/graphics_private.c"
            " src/fw/applib/graphics/graphics_private_raw.c"
            " src/fw/applib/graphics/graphics_circle.c"
            " src/fw/applib/graphics/graphics_line.c"
            " src/fw/applib/graphics/gtypes.c",
        test_sources_ant_glob="test_png.c",
        defines=ctx.env.test_image_defines,
        runtime_deps=filter(lambda x: 'test_png__' in str(x), ctx.env.test_pngs))

    clar(ctx,
        sources_ant_glob =
            " src/fw/applib/vendor/uPNG/upng.c"
            " src/fw/applib/vendor/tinflate/tinflate.c"
            " src/fw/applib/graphics/gbitmap.c" \
            " src/fw/applib/graphics/gbitmap_png.c"
            " src/fw/applib/graphics/gbitmap_sequence.c"
            " src/fw/applib/graphics/gcolor_definitions.c"
            " src/fw/applib/graphics/8_bit/bitblt_private.c"
            " src/fw/applib/graphics/framebuffer.c"
            " src/fw/applib/graphics/graphics.c"
            " src/fw/applib/graphics/bitblt.c"
            " src/fw/applib/graphics/graphics_private.c"
            " src/fw/applib/graphics/graphics_private_raw.c"
            " src/fw/applib/graphics/graphics_circle.c"
            " src/fw/applib/graphics/graphics_line.c"
            " src/fw/applib/graphics/gtypes.c"
            " src/fw/board/displays/display_spalding.c"
            " tests/fakes/fake_resource_syscalls.c",
        test_sources_ant_glob="test_gbitmap_sequence.c",
        defines=ctx.env.test_image_defines,
        runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis,
        platforms=['tintin', 'spalding'])

    clar(ctx,
        sources_ant_glob =
            " src/fw/applib/vendor/uPNG/upng.c"
            " src/fw/applib/vendor/tinflate/tinflate.c"
            " src/fw/applib/graphics/gtypes.c"
            " src/fw/applib/graphics/gbitmap.c" \
            " tests/fakes/fake_gbitmap_png.c"
            " src/fw/applib/graphics/gcolor_definitions.c"
            " src/fw/applib/graphics/8_bit/framebuffer.c"
            " src/fw/applib/graphics/framebuffer.c"
            " src/fw/applib/graphics/8_bit/bitblt_private.c"
            " src/fw/applib/graphics/bitblt.c"
            " src/fw/applib/graphics/graphics_private.c"
            " src/fw/applib/graphics/graphics_private_raw.c"
            " src/fw/applib/graphics/graphics_circle.c"
            " src/fw/applib/graphics/graphics_line.c"
            " src/fw/applib/graphics/graphics.c",
        test_sources_ant_glob="test_pbi.c",
        defines=ctx.env.test_image_defines,
        runtime_deps=filter(lambda x: 'test_pbi__' in str(x), ctx.env.test_pbis))

    clar(ctx,
        sources_ant_glob =
            " src/fw/applib/vendor/uPNG/upng.c"
            " src/fw/applib/vendor/tinflate/tinflate.c"
            " src/fw/applib/graphics/gtypes.c"
            " src/fw/applib/graphics/gbitmap.c" \
            " src/fw/applib/graphics/gbitmap_png.c"
            " src/fw/applib/graphics/gcolor_definitions.c"
            " src/fw/applib/graphics/8_bit/framebuffer.c"
            " src/fw/applib/graphics/framebuffer.c"
            " src/fw/applib/graphics/8_bit/bitblt_private.c"
            " src/fw/applib/graphics/bitblt.c"
            " src/fw/applib/graphics/graphics_private.c"
            " src/fw/applib/graphics/graphics_private_raw.c"
            " src/fw/applib/graphics/graphics_circle.c"
            " src/fw/applib/graphics/graphics_line.c"
            " src/fw/applib/graphics/graphics.c",
        test_sources_ant_glob="test_palettized_conversion.c",
        defines=ctx.env.test_image_defines,
        runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis)

    clar(ctx,
         sources_ant_glob=(
             "src/fw/applib/graphics/gtypes.c "
             "src/fw/apps/system_apps/timeline/text_node.c "
             "tests/stubs/stubs_text_layout.c "
         ),
         test_sources_ant_glob="test_graphics_text_node.c")


    clar(ctx,
        sources_ant_glob =
            " src/fw/applib/graphics/perimeter.c"
            " src/fw/applib/graphics/gtypes.c",
        test_sources_ant_glob="test_perimeter.c",
        test_libs=['m'],
        defines=defines,
        platforms=['snowy', 'spalding'])

    clar(ctx,
        sources_ant_glob =
            " src/fw/applib/graphics/gtypes.c"
            " src/fw/applib/graphics/gbitmap.c"
            " tests/fakes/fake_gbitmap_png.c"
            " src/fw/applib/graphics/gcolor_definitions.c"
            " src/fw/applib/graphics/${BITDEPTH}_bit/framebuffer.c"
            " src/fw/applib/graphics/framebuffer.c"
            " src/fw/applib/ui/layer.c"
            " src/fw/applib/graphics/${BITDEPTH}_bit/bitblt_private.c"
            " src/fw/applib/graphics/bitblt.c"
            " src/fw/applib/graphics/graphics_private.c"
            " src/fw/applib/graphics/graphics_private_raw.c"
            " src/fw/applib/graphics/graphics_circle.c"
            " src/fw/applib/graphics/graphics_line.c"
            " src/fw/applib/graphics/graphics.c",
        test_sources_ant_glob="test_graphics_draw_line.c",
        defines=ctx.env.test_image_defines,
        runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis,
        platforms=['tintin', 'snowy'])

    clar(ctx,
        sources_ant_glob =
            " src/fw/applib/vendor/uPNG/upng.c"
            " src/fw/applib/vendor/tinflate/tinflate.c"
            " src/fw/applib/graphics/gtypes.c"
            " src/fw/applib/graphics/gbitmap.c" \
            " src/fw/applib/graphics/gbitmap_png.c"
            " src/fw/applib/graphics/gcolor_definitions.c"
            " src/fw/applib/graphics/${BITDEPTH}_bit/framebuffer.c"
            " src/fw/applib/graphics/framebuffer.c"
            " src/fw/applib/graphics/${BITDEPTH}_bit/bitblt_private.c"
            " src/fw/applib/graphics/bitblt.c"
            " src/fw/applib/graphics/graphics_private.c"
            " src/fw/applib/graphics/graphics_private_raw.c"
            " src/fw/applib/graphics/graphics_circle.c"
            " src/fw/applib/graphics/graphics_line.c"
            " src/fw/applib/graphics/graphics.c",
        test_sources_ant_glob="test_bitblt_palette_1bit.c",
        defines=ctx.env.test_image_defines,
        runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis,
        platforms=['tintin'])

    clar(ctx,
        sources_ant_glob =
          " src/fw/applib/vendor/uPNG/upng.c"
          " src/fw/applib/vendor/tinflate/tinflate.c"
          " src/fw/applib/graphics/gbitmap.c"
          " src/fw/applib/graphics/gbitmap_png.c"
          " src/fw/applib/graphics/gcolor_definitions.c"
          " src/fw/applib/graphics/8_bit/framebuffer.c"
          " src/fw/applib/graphics/framebuffer.c"
          " src/fw/applib/graphics/graphics.c"
          " src/fw/applib/graphics/8_bit/bitblt_private.c"
          " src/fw/applib/graphics/bitblt.c"
          " src/fw/applib/graphics/graphics_private.c"
          " src/fw/applib/graphics/graphics_private_raw.c"
          " src/fw/applib/graphics/graphics_circle.c"
          " src/fw/applib/graphics/graphics_line.c"
          " src/fw/applib/graphics/gtypes.c"
          " src/fw/board/displays/display_spalding.c",
        test_sources_ant_glob="test_framebuffer_duma.c",
        defines=ctx.env.test_image_defines,
        platforms=['snowy', 'spalding'])

    clar(ctx,
        sources_ant_glob =
            " src/fw/applib/graphics/gtypes.c"
            " src/fw/applib/graphics/gbitmap.c"
            " tests/fakes/fake_gbitmap_png.c"
            " tests/fakes/fake_gbitmap_get_data_row.c"
            " src/fw/applib/graphics/gcolor_definitions.c"
            " src/fw/applib/graphics/8_bit/framebuffer.c"
            " src/fw/applib/graphics/framebuffer.c"
            " src/fw/applib/ui/layer.c"
            " src/fw/applib/graphics/8_bit/bitblt_private.c"
            " src/fw/applib/graphics/bitblt.c"
            " src/fw/applib/graphics/graphics_private.c"
            " src/fw/applib/graphics/graphics_private_raw.c"
            " src/fw/applib/graphics/graphics_circle.c"
            " src/fw/applib/graphics/graphics_line.c"
            " src/fw/applib/graphics/graphics.c",
        test_sources_ant_glob="test_graphics_draw_core.c",
        defines=ctx.env.test_image_defines,
        runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis,
        platforms=['snowy'])

    clar(ctx,
            sources_ant_glob =
                " src/fw/applib/graphics/gtypes.c"
                " src/fw/applib/graphics/gbitmap.c"
                " tests/fakes/fake_gbitmap_png.c"
                " tests/fakes/fake_gbitmap_get_data_row.c"
                " src/fw/applib/graphics/gcolor_definitions.c"
                " src/fw/applib/graphics/8_bit/framebuffer.c"
                " src/fw/applib/graphics/framebuffer.c"
                " src/fw/applib/ui/layer.c"
                " src/fw/applib/graphics/8_bit/bitblt_private.c"
                " src/fw/applib/graphics/bitblt.c"
                " src/fw/applib/graphics/graphics_private.c"
                " src/fw/applib/graphics/graphics_private_raw.c"
                " src/fw/applib/graphics/graphics_circle.c"
                " src/fw/applib/graphics/graphics_line.c"
                " src/fw/applib/graphics/graphics.c"
                " src/fw/board/displays/display_spalding.c",
            test_sources_ant_glob="test_framebuffer_clipping.c",
            defines=ctx.env.test_image_defines,
            runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis,
            platforms=['spalding'])

    clar(ctx,
                sources_ant_glob =
                    " src/fw/applib/graphics/gtypes.c"
                    " src/fw/applib/graphics/gbitmap.c"
                    " tests/fakes/fake_gbitmap_png.c"
                    " tests/fakes/fake_gbitmap_get_data_row.c"
                    " src/fw/applib/graphics/gcolor_definitions.c"
                    " src/fw/applib/graphics/${BITDEPTH}_bit/framebuffer.c"
                    " src/fw/applib/graphics/framebuffer.c"
                    " src/fw/applib/ui/layer.c"
                    " src/fw/applib/graphics/8_bit/bitblt_private.c"
                    " src/fw/applib/graphics/bitblt.c"
                    " src/fw/applib/graphics/graphics_private.c"
                    " src/fw/applib/graphics/graphics_private_raw.c"
                    " src/fw/applib/graphics/graphics_private_raw_mask.c"
                    " src/fw/applib/graphics/graphics_circle.c"
                    " src/fw/applib/graphics/graphics_line.c"
                    " src/fw/applib/graphics/graphics_mask.c"
                    " src/fw/applib/graphics/graphics.c"
                    " src/fw/applib/ui/window_stack_animation_round.c"
                    " tests/stubs/stubs_animation.c"
                    " src/fw/services/common/compositor/default/compositor_round_flip_transitions.c"
                    " src/fw/applib/ui/animation_interpolate.c"
                    " src/fw/board/displays/display_spalding.c",
                test_sources_ant_glob="test_graphics_window_stack_animation.c",
                defines=ctx.env.test_image_defines + ['CAPABILITY_HAS_MASKING=1'],
                runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis,
                platforms=['spalding'])

    clar(ctx,
                sources_ant_glob =
                    " src/fw/applib/graphics/gtypes.c"
                    " src/fw/applib/graphics/gbitmap.c"
                    " tests/fakes/fake_gbitmap_png.c"
                    " tests/fakes/fake_applib_resource.c"
                    " src/fw/applib/graphics/gcolor_definitions.c"
                    " src/fw/applib/graphics/${BITDEPTH}_bit/framebuffer.c"
                    " src/fw/applib/graphics/framebuffer.c"
                    " src/fw/applib/ui/layer.c"
                    " src/fw/applib/graphics/8_bit/bitblt_private.c"
                    " src/fw/applib/graphics/bitblt.c"
                    " src/fw/applib/graphics/graphics_private.c"
                    " src/fw/applib/graphics/graphics_private_raw.c"
                    " src/fw/applib/graphics/graphics_private_raw_mask.c"
                    " src/fw/applib/graphics/graphics_circle.c"
                    " src/fw/applib/graphics/graphics_line.c"
                    " src/fw/applib/graphics/graphics_mask.c"
                    " src/fw/applib/graphics/graphics.c"
                    " src/fw/board/displays/display_spalding.c",
                test_sources_ant_glob="test_graphics_context_mask.c",
                defines=ctx.env.test_image_defines + ['CAPABILITY_HAS_MASKING=1'],
                runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis,
                platforms=['snowy'])

    clar(ctx,
            sources_ant_glob =
                " src/fw/applib/graphics/gtypes.c"
                " src/fw/applib/graphics/gbitmap.c"
                " tests/fakes/fake_gbitmap_png.c"
                " tests/fakes/fake_gbitmap_get_data_row.c"
                " src/fw/applib/graphics/gcolor_definitions.c"
                " src/fw/applib/graphics/8_bit/framebuffer.c"
                " src/fw/applib/graphics/framebuffer.c"
                " src/fw/applib/ui/layer.c"
                " src/fw/applib/graphics/8_bit/bitblt_private.c"
                " src/fw/applib/graphics/bitblt.c"
                " src/fw/applib/graphics/graphics_private.c"
                " src/fw/applib/graphics/graphics_private_raw.c"
                " src/fw/applib/graphics/graphics_circle.c"
                " src/fw/applib/graphics/graphics_line.c"
                " src/fw/applib/graphics/graphics.c",
            test_sources_ant_glob="test_graphics_draw_implementation.c",
            defines=ctx.env.test_image_defines,
            runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis)

    clar(ctx,
        sources_ant_glob =
            " src/fw/applib/vendor/uPNG/upng.c"
            " src/fw/applib/vendor/tinflate/tinflate.c"
            " src/fw/applib/graphics/gtypes.c"
            " src/fw/applib/graphics/gbitmap.c"
            " src/fw/applib/graphics/gbitmap_png.c"
            " src/fw/applib/graphics/gcolor_definitions.c"
            " src/fw/applib/graphics/8_bit/framebuffer.c"
            " src/fw/applib/graphics/framebuffer.c"
            " src/fw/applib/graphics/8_bit/bitblt_private.c"
            " src/fw/applib/graphics/bitblt.c"
            " src/fw/applib/graphics/graphics_private.c"
            " src/fw/applib/graphics/graphics_private_raw.c"
            " src/fw/applib/graphics/graphics_circle.c"
            " src/fw/applib/graphics/graphics_line.c"
            " src/fw/applib/graphics/graphics.c"
            " src/fw/board/displays/display_$PLATFORM.c",
        test_sources_ant_glob="test_bitblt_circular.c",
        defines=ctx.env.test_image_defines,
        runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis,
        platforms=["spalding"])

    clar(ctx,
        sources_ant_glob =
            " src/fw/applib/graphics/gtypes.c"
            " src/fw/applib/graphics/gbitmap.c"
            " tests/fakes/fake_gbitmap_png.c"
            " tests/fakes/fake_gbitmap_get_data_row.c"
            " src/fw/applib/graphics/gcolor_definitions.c"
            " src/fw/applib/graphics/${BITDEPTH}_bit/framebuffer.c"
            " src/fw/applib/graphics/framebuffer.c"
            " src/fw/applib/ui/layer.c"
            " src/fw/applib/graphics/${BITDEPTH}_bit/bitblt_private.c"
            " src/fw/applib/graphics/bitblt.c"
            " src/fw/applib/graphics/graphics_private.c"
            " src/fw/applib/graphics/graphics_private_raw.c"
            " src/fw/applib/graphics/graphics_bitmap.c"
            " src/fw/applib/graphics/graphics_circle.c"
            " src/fw/applib/graphics/graphics_line.c"
            " src/fw/applib/graphics/graphics.c",
        test_sources_ant_glob="test_graphics_draw_rotated_bitmap.c",
        defines=ctx.env.test_image_defines,
        runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis,
        platforms=["tintin", "snowy"])

    ###############################
    # 8-bit specific bitblt tests #
    ###############################
    graphics_sources_ant_glob = \
        " src/fw/applib/graphics/gcolor_definitions.c" \
        " src/fw/applib/graphics/8_bit/framebuffer.c" \
        " src/fw/applib/graphics/framebuffer.c" \
        " src/fw/applib/graphics/8_bit/bitblt_private.c" \
        " src/fw/applib/graphics/gbitmap.c" \
        " src/fw/applib/graphics/gtypes.c" \
        " src/fw/applib/graphics/graphics.c" \
        " src/fw/applib/graphics/graphics_bitmap.c" \
        " src/fw/applib/graphics/gtransform.c" \
        " src/fw/applib/graphics/bitblt.c" \
        " src/fw/applib/ui/layer.c" \
        " tests/fakes/fake_gbitmap_png.c" \
        " tests/fakes/fake_display.c" \
        " src/fw/applib/graphics/graphics_private.c" \
        " src/fw/applib/graphics/graphics_private_raw.c" \
        " src/fw/applib/graphics/graphics_circle.c" \
        " src/fw/applib/graphics/graphics_line.c"

    graphics_test_sources_8bit = [
        "test_bitblt.c",
        "test_bitblt_palette.c"
    ]

    for test in graphics_test_sources_8bit:
        defines = ctx.env.test_image_defines

        clar(ctx,
             sources_ant_glob = graphics_sources_ant_glob,
             test_sources_ant_glob = test,
             defines=defines)

# vim:filetype=python
